/**
 * @author Jason Pratt
 */

package edu.cmu.cs.stage3.alice.authoringtool.datatransfer;

import java.awt.datatransfer.DataFlavor;

import edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool;
import edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources;

public class CommonMathQuestionsTransferable implements java.awt.datatransfer.Transferable {

 public static java.awt.datatransfer.DataFlavor commonMathQuestionsFlavor = AuthoringToolResources.getReferenceFlavorForClass( CommonMathQuestionsTransferable.class );

 protected java.awt.datatransfer.DataFlavor myFlavor;
 protected java.awt.datatransfer.DataFlavor[] flavors;

 public CommonMathQuestionsTransferable() {
  try { // src/edu/cmu/cs/stage3/alice/authoringtool/AuthoringToolResources.java: getReferenceFlavorForClass(...)
                // Leo: forcei inserir em 'src/edu/cmu/cs/stage3/alice/core/Element.java': 
                //      'static { s_classnameMap.put("edu.cmu.cs.stage3.alice.authoringtool.datatransfer.CommonMathQuestionsTransferable", edu.cmu.cs.stage3.alice.authoringtool.datatransfer.CommonMathQuestionsTransferable.class); }
      // myFlavor = AuthoringToolResources.getReferenceFlavorForClass( CommonMathQuestionsTransferable.class );
      // myFlavor = AuthoringToolResources.getReferenceFlavorForClass( this.getClass() );
      myFlavor = AuthoringToolResources.getReferenceFlavorForClass( edu.cmu.cs.stage3.alice.authoringtool.datatransfer.CommonMathQuestionsTransferable.class );
                    // this.getClass().newInstance();
      myFlavor.setHumanPresentableName( "commonMathQuestionsTransferable" );
  } catch( Exception e ) {
      System.err.println("Error: CommonMathQuestionsTransferable.java: myFlavor="+myFlavor);
             AuthoringTool.getInstance().showErrorDialog( e.getMessage(), e );
      return;
  }

  flavors = new java.awt.datatransfer.DataFlavor[2];
  flavors[0] = myFlavor;
  flavors[1] = java.awt.datatransfer.DataFlavor.stringFlavor;
 }

 public java.awt.datatransfer.DataFlavor[] getTransferDataFlavors() {
  return flavors;
 }

 public boolean isDataFlavorSupported( java.awt.datatransfer.DataFlavor flavor ) {
  //LOB for (DataFlavor flavor2 : flavors)
  int t_tam = flavors!=null ? flavors.length : 0;
  for (int i_i=0; i_i<t_tam; i_i++) {
   if( flavor.equals( flavors[i_i] ) ) { //L flavor.equals( flavor2 )
    return true;
   }
  }
  return false;
 }

 public Object getTransferData( java.awt.datatransfer.DataFlavor flavor ) throws java.awt.datatransfer.UnsupportedFlavorException, java.io.IOException {
  if( flavor.getRepresentationClass().equals( CommonMathQuestionsTransferable.class ) ) {
   return this;
  } else if( flavor.equals( java.awt.datatransfer.DataFlavor.stringFlavor ) ) {
   return this.toString();
  } else {
   throw new java.awt.datatransfer.UnsupportedFlavorException( flavor );
  }
 }

}
